package com.woaigsc.controller;

import com.woaigsc.pojo.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by chuiyuan on 3/15/16.
 */
@Controller
public class StudentController {

    @RequestMapping(value = "/student", method = RequestMethod.GET)
    public ModelAndView student(){
        return new ModelAndView("student","command", new Student());
    }

    @RequestMapping(value = "/addStudent",method = RequestMethod.POST)
    public String addStudent(@ModelAttribute("SpringWeb")Student student,
                             ModelMap modelMap){
        modelMap.addAttribute("age",student.getAge());
        modelMap.addAttribute("id", student.getId()) ;
        modelMap.addAttribute("name",student.getName());
        return "result";
    }
}
